package com.snoweagler.JmsSend;


import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.DefaultRedirectStrategy;
import org.springframework.security.web.RedirectStrategy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@RestController
@RequestMapping
public class UserController {

    private RedirectStrategy redirect = new DefaultRedirectStrategy();

    @RequestMapping("/login")
    public void loginIn(HttpServletRequest request, HttpServletResponse response) {
        try {
            redirect.sendRedirect(request, response, "/login.html");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @GetMapping("/index")
    public String getInfo() {
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
        return "hello world"+name;
    }
}
